package com.shroo8.footballblog.controllers.api;

import java.util.Locale;

import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;

import com.shroo8.footballblog.bo.api.CreateAuthorBo;
import com.shroo8.footballblog.dto.api.AuthorDto;

@Controller
public class CreateAuthorController {
	private static final Logger logger = LoggerFactory.getLogger(CreateAuthorController.class);

	@Resource(name="createAuthorBo", type=com.shroo8.footballblog.bo.api.CreateAuthorBoImpl.class)
	private CreateAuthorBo createAuthorBo;

	@RequestMapping(value = "/authors", method = RequestMethod.POST)
	public @ResponseBody String createAuthor(Locale locale, @RequestParam("authorType") String authorType, 
			@RequestParam("authorExternalId") String authorExternalId, @RequestParam("authorName") String authorName, 
			@RequestParam("authorScreenName") String authorScreenName,@RequestParam("authorPicUrl") String authorPicUrl, 
			@RequestParam("authorBigPicUrl") String authorBigPicUrl, @RequestParam("authorMiniPicUrl") String authorMiniPicUrl) {

		logger.info("Welcome to createAuthor! The client locale is {}.", locale);
		
		AuthorDto authorDto = new AuthorDto();
		authorDto.setType(authorType);
		authorDto.setExternalId(authorExternalId);
		authorDto.setName(authorName);
		authorDto.setScreenName(authorScreenName);
		authorDto.setPicUrl(authorPicUrl);
		authorDto.setBigPicUrl(authorBigPicUrl);
		authorDto.setMiniPicUrl(authorMiniPicUrl);
		
		return "{\"authorId\":\""+ createAuthorBo.createAuthor(authorDto) +"\"}"; 
	}

	public CreateAuthorBo getCreateAuthorBo() {
		return createAuthorBo;
	}

	public void setCreateAuthorBo(CreateAuthorBo createAuthorBo) {
		this.createAuthorBo = createAuthorBo;
	}

}
